<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class timely_report extends Page
{
       public $Image2 = null;
       public $cmbyearly = null;
       public $cmbyear = null;
       public $cmbmonth = null;
       public $btnDownload = null;
       public $JTDateReport = null;
       public $cmbReportType = null;
       public $lblmodel = null;
       public $lblmake = null;
       public $lblyr = null;
       public $Label43 = null;
       public $Label38 = null;
       public $lblyear = null;
       public $Label48 = null;
       public $lblVeh = null;
       public $Image1 = null;
       public $hiddenVeh = null;
       public $btnYearly = null;
       public $btnMonthly = null;
       public $btnDaily = null;
       public $JTSiteTheme1 = null;
       function timely_reportJSLoad($sender, $params)
       {
       //js can't modify visibility of elements that are declared
       //visible false using delphi property
       ?>
       var cal_field = document.getElementById('f-calendar-field-1');
       var cal_trigger = document.getElementById('f-calendar-trigger-1');
       var cmbyear = document.getElementById('cmbyear');
       var cmbmonth = document.getElementById('cmbmonth');
       var cmbyearly = document.getElementById('cmbyearly');

       cal_field.style.visibility = 'visible';
       cal_trigger.style.visibility = 'visible';
       cmbyear.style.visibility = 'hidden';
       cmbmonth.style.visibility = 'hidden';
       cmbyearly.style.visibility = 'hidden';
       <?php

       }

       function cmbReportTypeJSChange($sender, $params)
       {
       ?>
       var cal_field = document.getElementById('f-calendar-field-1');
       var cal_trigger = document.getElementById('f-calendar-trigger-1');
       var cmbyear1 = document.getElementById('cmbyear_outer');
       var cmbmonth1 = document.getElementById('cmbmonth_outer');
       var cmbyearly1 = document.getElementById('cmbyearly_outer');
       var cmbyear = document.getElementById('cmbyear');
       var cmbmonth = document.getElementById('cmbmonth');
       var cmbyearly = document.getElementById('cmbyearly');
       var date = document.getElementById('JTDateReport');

       var dropdown = document.getElementById('cmbReportType');
       var indexval = dropdown.value;

       if(indexval=='1')
       {
        cal_field.style.visibility = 'visible';
        cal_trigger.style.visibility = 'visible';
        cmbyear.style.visibility = 'hidden';
        cmbmonth.style.visibility = 'hidden';
        cmbyearly.style.visibility = 'hidden';
        cmbyear1.style.left = '220px';
        cmbmonth1.style.left = '320px';
        cmbyearly1.style.left = '220px';
       }
       if(indexval=='2')
       {
        cal_field.style.visibility = 'hidden';
        cal_trigger.style.visibility = 'hidden';
        cmbyear.style.visibility = 'visible';
        cmbmonth.style.visibility = 'visible';
        cmbyearly.style.visibility = 'hidden';
        cmbyear1.style.left = '12px';
        cmbmonth1.style.left = '112px';
        cmbyearly1.style.left = '220px';
       }
       if(indexval=='3')
       {
        cal_field.style.visibility = 'hidden';
        cal_trigger.style.visibility = 'hidden';
        cmbyear.style.visibility = 'hidden';
        cmbmonth.style.visibility = 'hidden';
        cmbyearly.style.visibility = 'visible';
        cmbyear1.style.left = '220px';
        cmbmonth1.style.left = '320px';
        cmbyearly1.style.left = '12px';
       }
       <?php

       }

       function btnDownloadClick($sender, $params)
       {
        $type = $this->cmbReportType->getItemIndex();
        if($type=='1')
        {
         $daily = $this->JTDateReport->getText().'%';
         redirect('veh_reports.php?report_date='.$daily.'&veh='.$this->hiddenVeh->getValue().'&type=d');
        }
        if($type=='2')
        {
         $monthly = $this->cmbyear->getItemIndex().'-'.$this->cmbmonth->getItemIndex().'-%';
         redirect('veh_reports.php?report_date='.$monthly.'&veh='.$this->hiddenVeh->getValue().'&type=m');
        }
        if($type=='3')
        {
         $yearly = $this->cmbyearly->getItemIndex().'-%'.'-%';
         redirect('veh_reports.php?report_date='.$yearly.'&veh='.$this->hiddenVeh->getValue().'&type=y');
        }


       }

       function cmbReportTypeChange()
       {
        $type = $this->cmbReportType->getItemIndex();
        if($type=='1')
        {
         $this->JTDateReport->Visible=true;
         $this->cmbyear->setVisible(false);
         $this->cmbmonth->setVisible(false);
         $this->cmbyearly->setVisible(false);
        }
        if($type=='2')
        {
         $this->JTDateReport->Visible=false;
         $this->cmbyear->setVisible(true);
         $this->cmbmonth->setVisible(true);
         $this->cmbyearly->setVisible(false);
        }
        if($type=='3')
        {
         $this->JTDateReport->Visible=false;
         $this->cmbyear->setVisible(false);
         $this->cmbmonth->setVisible(false);
         $this->cmbyearly->setVisible(true);
        }

       }

       function timely_reportCreate($sender, $params)
       {
       $veh = $_GET['veh'];
       $xxx = $_GET['xxx'];
       if($veh!=null | $veh!='')
       $this->hiddenVeh->setValue(base64_decode($veh));

       /*echo "<script type=text/javascript>
       alert('".base64_decode($veh)."');
       alert('".base64_decode($xxx)."');
       </script>";*/

       $this->JTDateReport->Text = (date('Y-m-d'));
       $this->cmbReportType->setItemIndex('1');
       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$this->hiddenVeh->getValue()."'")or die(mysql_error());
       $row_selected = mysql_fetch_array($result_vin);
       $label = $row_selected['VIN'];
       $this->lblVeh->Caption = $label;
       $this->lblyr->Caption = $row_selected['year'];
       $this->lblmake->Caption = $row_selected['manufacturer_name'];
       $this->lblmodel->Caption = $row_selected['model_name'];

       $ctr = 1950;
       $this->cmbyear->Clear();
       $this->cmbyear->setItemIndex(date('Y'));
       $this->cmbyearly->Clear();
       $this->cmbyearly->setItemIndex(date('Y'));
       while($ctr<=2200)
       {
        $this->cmbyear->AddItem($ctr, null, $ctr);
        $this->cmbyearly->AddItem($ctr, null, $ctr);
        $ctr++;
       }
       }

       function btnYearlyClick($sender, $params)
       {
       $yearly = $this->cmbyearly->getItemIndex().'-%'.'-%';
       redirect('veh_reports.php?report_date='.$yearly.'&veh='.$this->hiddenVeh->getValue().'&type=y.');
       }

       function btnMonthlyClick($sender, $params)
       {
       $monthly = $this->cmbyear->getItemIndex().'-'.$this->cmbmonth->getItemIndex().'-%';
       redirect('veh_reports.php?report_date='.$monthly.'&veh='.$this->hiddenVeh->getValue().'&type=m.');
       }

       function btnDailyClick($sender, $params)
       {
       $daily = $this->JTDateReport->getDate().'%';
       redirect('veh_reports.php?report_date='.$daily.'&veh='.$this->hiddenVeh->getValue().'&type=d.');
       }

}

global $application;

global $timely_report;

//Creates the form
$timely_report=new timely_report($application);

//Read from resource file
$timely_report->loadResource(__FILE__);

//Shows the form
$timely_report->show();

?>